package qf.dao.daoImpl;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import qf.dao.UserDao;
import qf.pojo.User;
import qf.utils.DBUtil;

import java.sql.SQLException;

/**
 * @author 86198
 * @version V1.0
 * @Project Java_qf
 * @Package qf.dao
 * @Description:
 * @Date 2022/5/21 15:07
 */
public class UserDaoImpl implements UserDao {
private QueryRunner qr = new QueryRunner(DBUtil.getDateSource());
    @Override
    public User findUsername(String username) {
        String sql="select * from tb_user where username=?";
        try {
            return qr.query(sql, new BeanHandler<User>(User.class), username);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public int registerUser(User user) {
        String sql = "insert into tb_user (username,password,email,gender,status,role,code)values(?,?,?,?,?,?,?)";
        try {
            return qr.update(sql,user.getUsername(),user.getPassword(),user.getEmail(),user.getGender(),user.getStatus(),user.getRole(),user.getCode());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }
}
